<?php

	/*
	*	对提交的信息进行操作
	*	检查并插入到数据库
	*/
	

	class ResumeModel {
		
		private $tableKeyList;
		
		private $tableValueList;
		
		public function __construct($_post, $_files) {
			
			$this->tableKeyList = array (
			
				'name',
				'gender',
				'birthday',
				'email','tell',
				'school',
				'major',
				'hobby',
				'has_annex',
				'statu'
				
			);
			
		}
		
		
		//	组建sql语句
		public function sqlBuild() {
			
			$_POST['has_annex'] = 0;
			
			if(!empty($_FILES['resume_annex']['name'])) {
				
				$_POST['has_annex'] = 1;
				
			}
			
			$_POST['year'] .= '-';
			
			$_POST['year'] .= $_POST['month'];
			
			$_POST['birthday'] = $_POST['year'];
			
			$_POST['birthday'] = '1990-7';
			
			$_POST['email'] = $_POST['personMail'];
			
			$_POST['statu'] = 1;
			
			foreach($this->tableKeyList as $k => $v) {
				
				$this->tableValueList[$v] = $_POST[$v];
				
			}
			
		}
		
		
		//	将获取到的数据插入到数据库
		public function addToDatabase() {
			
			$this->sqlBuild();
			
			$table = new DataTableModel();
			
			$table->insert($this->tableKeyList, $this->tableValueList);
			
		}
		
		
		//	检查提交到服务器的信息
		public function checkInfo() {
			
			$ck_handle = new Check();
			
			if(!$ck_handle->checkName()) {

				return 1;
				
			}
			
			if(!$ck_handle->checkMail()) {
				
				return 2;
				
			}
			
			
			if(!$ck_handle->checkTell()) {
				
				return 3;
				
			}
	
			if(!$ck_handle->checkSchool()) {
				
				return 4;
				
			}
			
			if(!empty($_FILES['resume_annex']['name'])) {
				
				$this->has_annex = 1;
				
				$ck_handle->checkFile($_FILES['resume_annex']['name']);
			}
			
			return false;
		}
	}
?>